<template>
	<view class="">
		<!-- 选择收获地址的盒子 -->
		<view class="address-container" v-if="JSON.stringify(address) === '{}'">
			<button type="primary" size="mini" @click="chooseAddress">请添加收货地址+</button>
		</view>
		<!-- 设置收获地址的盒子 -->
		<!-- 打桩 -->
		<view class="address-detail" v-else @click="chooseAddress">
			<view class="row1">
				<view class="left">收货人: {{address.userName}}</view>
				<view class="phone">
					<view class="right">电话: {{address.telNumber}}</view>
					<uni-icons type="right" size="14" color="#000000"></uni-icons>
				</view>

			</view>
			<view class="row2">
				<view class="left">收货地址: </view>
				<view class="right">{{fullAddress}}</view>
			</view>
		</view>
		<!-- 底部 -->
		<image class="address-border" src="@/static/cart_border@2x.png" mode=""></image>
	</view>
</template>
<script>
	import{mapState, mapMutations, mapGetters} from 'vuex'
	export default {
		data() {
			return {
			}
		},
		methods:{
			...mapMutations('user', ['setAddress']),
			async chooseAddress() {
				const res = await uni.chooseAddress()
				if(res[0] === null && res[1].errMsg === "chooseAddress:ok") {
					this.setAddress(res[1])
				}
			},
			openSetting() {
				uni.openSetting({
					success: (res) => {
						console.log(res)
					}
				})
			}
		},
		computed:{
			...mapState('user', ['address']),
			...mapGetters('user', ['fullAddress'])
		}
	}
</script>
<style lang="scss">
	.address-border {
		width: 100%;
		height: 5px;
		display: block;
	}

	.address-container {
		height: 100px;
		display: flex;
		align-items: center;
		justify-content: center;
	}


	.address-detail {
		height: 100px;
		font-size: 14px;
		padding: 0 10px;
		display: flex;
		flex-direction: column;
		justify-content: center;

		.row1 {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 10px 0;

			.phone {
				display: flex;
				align-items: center;
			}
		}

		.row2 {
			margin-bottom: 10px;
			display: flex;
			align-items: center;
			// justify-content: space-between;

			.left {
				margin-right: 10px;
				white-space: nowrap;
			}

			.right {
				word-break: break-all;
			}
		}
	}
</style>